#!/bin/sh

gamename=`cat $PWD/GAMENAME`

##################  game wine script dev

filevername_script_dev="ztime-wine-script-game.ver"

rm -f "/tmp/$filevername_script_dev"

wget -c -nc -P /tmp http://ztime-wine-script-game.googlecode.com/files/$filevername_script_dev

ver_script_dev=`cat $PWD/$filevername_script_dev`
vernew_script_dev=`cat /tmp/$filevername_script_dev`

echo "Версия установленых скриптов $ver_script_dev  Версия скриптов в архиве на сайте $vernew_script_dev"

if [ "$ver_script_dev" -eq "$vernew_script_dev" ];
then
echo "Обновлений нет"
rm -f /tmp/$filevername_script_dev
else
echo "Обновки есть - качаем и ставим"
cd "`dirname "$0"`"
wget -c -nc -P $PWD http://ztime-wine-script-game.googlecode.com/files/ztime-wine-script-game.tar.gz
tar xvfz ztime-wine-script-game.tar.gz
rm ztime-wine-script-game.tar.gz
cp $PWD/ztime-wine-script-game/* $PWD
rmdir --ignore-fail-on-non-empty $PWD/ztime-wine-script-game
rm $PWD/$filevername_script_dev
cp /tmp/$filevername_script_dev $PWD
rm /tmp/$filevername_script_dev
fi

##################  game script

filevername_wine=$gamename\_script.ver

rm -f /tmp/$filevername_script

wget -c -nc -P /tmp https://github.com/downloads/zaharchuktv/files/$filevername_script

ver_script=`cat $PWD/$filevername_script`
vernew_script=`cat /tmp/$filevername_script`

echo "Версия установленых скриптов $ver_script  Версия скриптов в архиве на сайте $vernew_script"

if [ "$ver_script" -eq "$vernew_script" ];
then
echo "Обновлений нет"
rm -f /tmp/$filevername_script
else
echo "Обновки есть - качаем и ставим"
rm  $PWD/$filevername_script
fi


################# wine_distrib

filevername_wine=$gamename\_wine.ver

rm -f /tmp/$filevername_wine

wget -c -nc -P /tmp https://github.com/downloads/zaharchuktv/files/$filevername_wine

ver_wine=`cat $PWD/$filevername_wine`
vernew_wine=`cat /tmp/$filevername_wine`

echo "Версия установленного бинарного wine $ver_wine  Версия wine в архиве на сайте $vernew_wine"

if [ "$ver_wine" -eq "$vernew_wine" ];
then
echo "Обновлений нет"
rm -f /tmp/$filevername_wine
else
echo "Обновновился wine - качаем и ставим"
killall wineserver
cd "`dirname "$0"`"
wget -c -nc -P $PWD https://github.com/downloads/zaharchuktv/files/$filevername_wine
rmdir -p --ignore-fail-on-non-empty $PWD/wine_distrib
tar xvfz $PWD/wine_distrib.tar.gz
rm $PWD/wine_distrib.tar.gz
rm -f $PWD/$filevername_wine
#mv /tmp/$filevername_wine $PWD/$filevername_wine
rm -f $PWD/wine_distrib.tar.gz
./wine --version
fi


